Skip to content

Add IoT Metrics Support#809

Open
xiazhvera wants to merge 38 commits intomainfrom
iot_metrics
Open

Add IoT Metrics Support#809
xiazhvera wants to merge 38 commits intomainfrom
iot_metrics

Conversation

@xiazhvera
Copy link
Contributor

@xiazhvera xiazhvera commented Dec 19, 2025

Issue #, if available:

Description of changes:

  • Bind IoTDeviceSDKMetrics and metrics related features , CRT is now appending AWS metrics by default.
  • Add enableMetrics option to allow user disable metrics.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

/* Error */
int m_lastError;

/** Enable AWS IoT Metrics Collection. This is always set to true for now. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trivial: Maybe it'll become clearer below but what does this mean it's always set to true? Is this not tied to the enableMetrics bools that can be set to false?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this can't be changed to false. Is there a reason we're not allowing metrics to be disabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This option was originally there to match MQTT3 behavior, which allows users to disable metrics. Since the MQTT5 client does not supports toggling metrics collection, it should be safe to remove.

Copy link
Contributor

@sbSteveK sbSteveK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add what enable metrics defaults to in some locations and add tests that turning them off results in an unpadded username.

Comment on lines 675 to 676
Crt::String m_sdkName = "CPPv2";
Crt::String m_sdkVersion = AWS_CRT_CPP_VERSION;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part sill confuses me. Will the library name sometimes be set to CPPv2 (if mqtt client created with builder) and sometimes to IoTDeviceSDK/CPP (if created without builder) ? Can we change the default value of m_sdkName to IoTDeviceSDK/CPP ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned here, the SDK already exposes an API for setting a customized sdkName.
As we will introduce metadata later, once metadata is there, we will update the SDKs in a single change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I understand that we can't remove this. But we can change the default value. Or am I missing something?

aws_string_destroy(password);
return AWS_OP_SUCCESS;
}
AWS_TEST_CASE(Mqtt311DirectConnectionWithMetricsCollection, s_TestMqtt311DirectConnectionWithMetricsCollection)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should be added to tests/CMakeLists.txt

Comment on lines +691 to +697
/**
* Enable AWS IoT metrics. Default to enabled.
*
* @param enabled enable AWS IoT metrics to collect SDK usage data
* @return this option object
*/
Mqtt5ClientOptions &WithMetricsCollection(bool enabled) noexcept;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should provide more details to users about what info we collect (version, configuration, etc.) and what we don't (probably something general like "private data" would suffice), so users won't opt out of metrics just in case we collect something they don't want to share.
I'd add these details to all public API that expose metrics-related functionality.

Comment on lines +477 to +480
struct aws_mqtt_iot_metrics metrics;
AWS_ZERO_STRUCT(metrics);
m_sdkMetrics.initializeRawOptions(metrics);
if (aws_mqtt_client_connection_set_metrics(m_underlyingConnection, &metrics))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be possible to add meta info into metrics later on? For example, afaiks the cleanSession flag is not available at this point, so we'll have to add it to metrics at the connection time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants